function SearchController(view) {
	this.view = view;
	var sc = this; 
	
	this.init = function() {
		$('#send_search_action').click(function(){
			sc.sendSearch(this);
		});
        $('#clean_search_action').click(function(){
			sc.cleanSearch(this);
		});
        
        $(function() {
            $( "#search_from_date_picker" ).datepicker({
                changeMonth: true,
                dateFormat: "yy-mm-dd"  
                /*onSelect: function(dateText, inst) {
                    $('#date_from_search_form').val(dateText);
                }*/
            });
            $( "#search_to_date_picker" ).datepicker({
                changeMonth: true,
                dateFormat: "yy-mm-dd"
                /*onSelect: function(dateText, inst) {
                    $('#date_to_search_form').val(dateText);
                }*/
            });
        });
        this.sendSearch();
    },
    
    this.sendSearch = function() {
        var post_data = new Object();
        var start = $('#search_from_date_picker').val();
        var end = $('#search_to_date_picker').val();
        var place = $('#start_place_search_form').val();
        if(start != "" && end != "") {
            post_data.start_date = start;
            post_data.end_date = end;
        }
        if(place != "") {
            post_data.start_place = place;
        }
        $.ajax({
            type: "POST",
            url: "cars_list.htm",
            data: post_data,
            dataType: "json",
            success: function(response) {
                if (response.res == "false") {
                    alert(response.error);
                }
                sc.view.reloadGreed(response.list);
            }
        });
    },
    
    this.cleanSearch = function() {
        $('#date_from_search_form').val('');
        $('#date_to_search_form').val('');
        $('#start_place_search_form').val('');
        this.sendSearch();    
    }
}

